# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Sven Wick <sven.wick@gmx.de>

pkgname=ssh-tools
pkgver=1.7
pkgrel=2
pkgdesc="A collection of tools making SSH more convenient"
arch=('any')
url="https://github.com/vaporup/ssh-tools"
license=('GPL')
depends=('openssh')
optdepends=('colordiff: colors for ssh-diff')
makedepends=('git' 'help2man')
_commit='fbf979f8a4f002a94ec2f487885aeebec49f80cb'
source=("$pkgname::git+$url.git#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  mkdir man
}

build() {
  cd "$pkgname"

  # dict with command:description pairings
  declare -A pages
  pages["ssh-ping"]="check if host is reachable using ssh_config"
  pages["ssh-version"]="shows version of the ssh server you are connecting to"
  pages["ssh-diff"]="diff a file over ssh"
  pages["ssh-facts"]="get some facts about the remote system"
  pages["ssh-hostkeys"]="prints server host keys in several formats"
  pages["ssh-keyinfo"]="prints keys in several formats"
  pages["ssh-certinfo"]="shows validity and information of ssh certificates"
  pages["ssh-force-password"]="enforces password authentication"

  # generate man pages
  for page in "${!pages[@]}"; do
    help2man \
      --name "${pages[${page}]}" \
      --source "${pkgname^^}" \
      --no-info \
      --version-string "$pkgver" \
      --output "man/${page}.1" \
     "./${page}"
  done
}

package() {
  cd "$pkgname"

  # scripts
  install -vDm755 -t "$pkgdir/usr/bin" ssh-*

  # man pages
  install -vDm644 -t "$pkgdir/usr/share/man/man1" man/*

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md
}
